package by.grsu.hdm.devices;

import java.util.Random;

import by.grsu.hdm.model.HomeDevice;
import by.grsu.hdm.model.HomeDeviceStatus;
import by.grsu.hdm.model.INetworkAvailable;
import by.grsu.hdm.model.USBPort;

public class MediaCenter extends HomeDevice implements INetworkAvailable {

	private long trafficIn;

	private long trafficOut;

	private MediaPlayer mediaPlayer;

	private USBPort usbPort;

	public MediaCenter(String id) {
		super();
		this.id=id;
		mediaPlayer = new MediaPlayer();
		status= new HomeDeviceStatus("The device "
				+ getDeviceId() + " is ready for use" + " ");

		defaultConfiguration();
	}

	public void defaultConfiguration() {
		trafficIn = 0;
		trafficOut = 0;
		usbPort = null;
	}

	@Override
	public long getOutgoingTraffic() {
		return trafficOut;
	}

	@Override
	public long getIncomingTraffic() {

		return trafficIn;
	}

	public void setUsbPort(String UsbId) {
		usbPort = new USBPort(UsbId);

	}

	public USBPort getUSBPort() {
		Random rnd = new Random(47);
		if (this.usbPort == null) {
			this.usbPort = new USBPort("USBport#" + rnd.nextInt(1000));
		}

		return usbPort;
	}

	public void beforeTurningOn() {
		Random rnd = new Random(47);
		trafficIn = rnd.nextLong();
		trafficOut = rnd.nextLong();

	}

	public void afterTurningOff() {
		Random rnd = new Random(47);
		trafficIn += rnd.nextLong();
		trafficOut += rnd.nextLong();

	}

	public String getDeviceId() {
		return super.getDeviceId();
	}

	public MediaPlayer contactMediaPlayer(){
		return mediaPlayer;
	}
}
